package hasalah.demo.client.views;

import hasalah.demo.client.services.BackendService;
import hasalah.demo.client.services.BackendServiceAsync;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;

public class EconomyConfigurationComposite extends Composite {

	private BackendServiceAsync backendServiceAsync = (BackendServiceAsync)GWT.create(BackendService.class);
	
	public EconomyConfigurationComposite() {
		
		FlexTable formTable = new FlexTable();

		initWidget(formTable);
		formTable.addStyleName("cw-FlexTable");
		formTable.setWidth("600px");
		formTable.setCellSpacing(5);
		formTable.setCellPadding(3);

		// Currency Name
		Label	nmbLabel = new Label("Currency Name", false);
		TextBox nmbText  = new TextBox();
		nmbText.setText("Point");
		formTable.setWidget(1, 1, nmbLabel);
		formTable.setWidget(1, 2, nmbText);
		
		Label lblBusinessName = new Label("Business Name", false);
		formTable.setWidget(2, 1, lblBusinessName);
		
		TextBox textBox = new TextBox();
		formTable.setWidget(2, 2, textBox);

		Button pressMe = new Button();
		
		pressMe.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				// TODO Auto-generated method stub
				backendServiceAsync.saveEconomy(new AsyncCallback<String>() {
					
					@Override
					public void onSuccess(String result) {
						
						Window.alert(result);
						
					}
					
					@Override
					public void onFailure(Throwable caught) {
					
						
						Window.alert("Failed!!!");
						
			
						
					}
				});
			}
		});
		
		formTable.setWidget(3, 1, pressMe);
	}

}
